<?php
session_start();
if (isset($_POST['openid']) && !empty($_POST['openid'])){
    include '../c/config.php';
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {}
    $openid=addslashes(trim($_POST['openid']));
    $type=addslashes(trim($_POST['type']));
    $sid=addslashes(trim($_POST['sid']));
    
    $query=$mysqli->query("SELECT id FROM qdui where openid='".$openid."' limit 0,1  ");
    if($query->num_rows>0){}else{
        
        echo json_encode(array('s'=>'n','n'=>'acess'));
        exit;
    }
    
    if('bao' == $type){
        $query=$mysqli->query("SELECT id FROM `qdui` where openid='".$openid."' limit 0,1 ");
        if($query->num_rows>0){
            $getQ=$query->fetch_assoc();
            $query=$mysqli->query("SELECT id FROM `baoming` where openid='".$openid."' and sid='".$sid."' limit 0,1 ");
            if($query->num_rows>0){}else{
                $querySaiSi=$mysqli->query("SELECT name FROM `saisi` where id='".$sid."' limit 0,1 ");
                $getSaiSi=$querySaiSi->fetch_assoc();
                if($querySaiSi->num_rows>0){
                    $mysqli->query("insert into baoming(openid,sid,sname,qid,createtime) values('".$openid."','".$sid."','".$getSaiSi['name']."','".$getQ['id']."','".date("Y-m-d H:i:s")."')  ");
                }
            }
        }
    }else{
        $mysqli->query("delete from baoming where openid='".$openid."' and sid='".$sid."'  ");
    }
    
    
    
    $mysqli->close();
    
    echo json_encode(array('s'=>'y'));
}

